/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddOptions.java
 *
 * Created on Jul 7, 2012, 10:35:34 AM
 */
package monitor;

import java.awt.Component;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import java.awt.Container;
import java.awt.Color;

/**
 *
 * @author FrostBiteX77
 */
public class AddTutor extends javax.swing.JFrame {
    
    int sFlag;
    private Component frame;
    int courseCount = 0;
    String mode;
    private Container c;
    
    
    /** Creates new form AddOptions */
    public AddTutor() {
        initComponents();
        mode = "Tutor";
        
        c = getContentPane();
        c.setBackground(Color.white);
        
        courseList1.removeAllItems();
        courseList2.removeAllItems();
        courseList3.removeAllItems();
        
        courseTxt2.setVisible(false);
        selectLabel2.setVisible(false);
        courseGrade2.setVisible(false);
        gradeLabel2.setVisible(false);
        courseList2.setVisible(false);
        
        
        courseTxt3.setVisible(false);
        selectLabel3.setVisible(false);
        courseGrade3.setVisible(false);
        gradeLabel3.setVisible(false);
        courseList3.setVisible(false);
        
        courseList1.addItem("");
        courseList2.addItem("");
        courseList3.addItem("");
       
        QHandler queryHandler = new QHandler();
        DBManager con = new DBManager();
        con.Connect();
        queryHandler.viewCourse();
        con.PullCourse(queryHandler.query, mode);
        con.Disconnect(con.rs);
        
     
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        fNameTxt = new javax.swing.JTextField();
        mNameTxt = new javax.swing.JTextField();
        lNameTxt = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        IDTxt = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        BtnM = new javax.swing.JRadioButton();
        BtnF = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        CGPATxt = new javax.swing.JTextField();
        BtnSubmit = new javax.swing.JButton();
        BtnCancel = new javax.swing.JButton();
        BtnClear = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        courseTxt1 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        eaddTxt = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        contactTxt = new javax.swing.JTextField();
        selectLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        selectLabel2 = new javax.swing.JLabel();
        courseTxt2 = new javax.swing.JTextField();
        selectLabel3 = new javax.swing.JLabel();
        courseTxt3 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        remarkTxt = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        courseList1 = new javax.swing.JComboBox();
        courseList2 = new javax.swing.JComboBox();
        courseList3 = new javax.swing.JComboBox();
        gradeLabel1 = new javax.swing.JLabel();
        gradeLabel2 = new javax.swing.JLabel();
        gradeLabel3 = new javax.swing.JLabel();
        courseGrade1 = new javax.swing.JTextField();
        courseGrade2 = new javax.swing.JTextField();
        courseGrade3 = new javax.swing.JTextField();
        degreeBox = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Add Tutor");
        setName("Add Tutor"); // NOI18N

        jLabel1.setText("TUTOR INFORMATION");

        jLabel2.setText("Name");

        fNameTxt.setName(""); // NOI18N

        jLabel6.setText("ID Number");

        IDTxt.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                IDTxtCaretUpdate(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        BtnM.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(BtnM);
        BtnM.setText("Male");

        BtnF.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(BtnF);
        BtnF.setText("Female");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BtnM)
                    .addComponent(BtnF))
                .addContainerGap(79, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(BtnM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BtnF)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jLabel8.setText("Degree Program");

        jLabel9.setText("CGPA");

        CGPATxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CGPATxtActionPerformed(evt);
            }
        });

        BtnSubmit.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnSubmit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Add2.png"))); // NOI18N
        BtnSubmit.setText("Add");
        BtnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnSubmitActionPerformed(evt);
            }
        });

        BtnCancel.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Cancel.png"))); // NOI18N
        BtnCancel.setText("Cancel");
        BtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCancelActionPerformed(evt);
            }
        });

        BtnClear.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnClear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Clear2.png"))); // NOI18N
        BtnClear.setText("Clear All");
        BtnClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnClearActionPerformed(evt);
            }
        });

        jLabel3.setText("Course Offered:");

        jLabel7.setText("Gender");

        jLabel4.setText("Email Address");

        jLabel5.setText("Contact Number");

        selectLabel1.setText("or select from this list");

        jButton1.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/course2.png"))); // NOI18N
        jButton1.setText("Add Course");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        selectLabel2.setText("or select from this list");

        selectLabel3.setText("or select from this list");

        jLabel11.setText("First Name");

        jLabel12.setText("Middle Name");

        jLabel13.setText("Last Name");

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jLabel10.setText("Remarks");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(remarkTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(remarkTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap())
        );

        courseList1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        courseList2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        courseList3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        gradeLabel1.setText("Grade");

        gradeLabel2.setText("Grade");

        gradeLabel3.setText("Grade");

        degreeBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-your degree program-", "CS-CSE", "CS-NE", "CS-ST", "INSYS", "CS-IST" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(BtnSubmit)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(BtnClear)
                        .addGap(18, 18, 18)
                        .addComponent(BtnCancel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(courseTxt3)
                            .addComponent(courseTxt2)
                            .addComponent(courseTxt1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(selectLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(selectLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(selectLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(courseList3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(courseList2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(courseList1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(gradeLabel3)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(gradeLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(gradeLabel2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(courseGrade3)
                            .addComponent(courseGrade2)
                            .addComponent(courseGrade1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(91, 91, 91))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eaddTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(IDTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(fNameTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel11))
                            .addComponent(contactTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(CGPATxt, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(degreeBox, 0, 164, Short.MAX_VALUE))
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jLabel12))
                                    .addComponent(mNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(24, 24, 24)
                                        .addComponent(jLabel13))
                                    .addComponent(lNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {CGPATxt, IDTxt, contactTxt, degreeBox, eaddTxt, fNameTxt});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(fNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addComponent(lNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(jLabel12))
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(IDTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(eaddTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(contactTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(degreeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(CGPATxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)))
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(courseTxt1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(selectLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(courseTxt2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(selectLabel2))
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(courseTxt3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(selectLabel3)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(courseGrade1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(courseGrade2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(courseList1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(gradeLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(courseList2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(gradeLabel2))))
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(courseList3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(gradeLabel3)
                            .addComponent(courseGrade3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {courseGrade1, courseGrade2, courseGrade3, courseList1, courseList2, courseList3, courseTxt1, courseTxt2, courseTxt3, gradeLabel1, gradeLabel2, gradeLabel3, selectLabel1, selectLabel2, selectLabel3});

        BtnSubmit.getAccessibleContext().setAccessibleName("");
        BtnCancel.getAccessibleContext().setAccessibleName("");
        BtnClear.getAccessibleContext().setAccessibleName("");
        jButton1.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void BtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelActionPerformed
// TODO add your handling code here:
    AddOptions add = new AddOptions();
    add.setVisible(true);
    add.setLocationRelativeTo(null);
    this.dispose();
    
    
}//GEN-LAST:event_BtnCancelActionPerformed

private void BtnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnSubmitActionPerformed
// TODO add your handling code here:
    
    //add if statement for textfields
    DBManager con1 = new DBManager();
    con1.Connect();
      //add if statement for textfields
    DBManager con2 = new DBManager();
    con2.Connect();
    
    DBManager con3 = new DBManager();
    con3.Connect();
    
    
    char gender;
    if(BtnM.isSelected())
        gender = 'M';
     
    else if(BtnF.isSelected())
        gender = 'F';
    
    else gender = '0';
    
        
    Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
    Matcher m = p.matcher(eaddTxt.getText());
    boolean matchFound = m.matches();
    
    
    if((IDTxt.getText().equals("")) 
            || (fNameTxt.getText().equals(""))  
            || (lNameTxt.getText().equals(""))
            || (eaddTxt.getText().equals(""))
            || (gender == '0')
            || (CGPATxt.getText().equals(""))
            || (courseGrade1.getText().equals(""))
            || ((courseTxt1.getText().equals(""))) && ((courseList1.getSelectedItem().equals("")))){
        
        JOptionPane.showMessageDialog(frame,
        "Please Complete all Fields.",
        "Incomplete",
        JOptionPane.WARNING_MESSAGE);
    }
    
    else if((!(courseTxt1.getText().equals(""))) && (!(courseList1.getSelectedItem().equals("")))){
        JOptionPane.showMessageDialog(frame,
        "Please fill-in only one course per selection.",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
    }
    
     else if(!(Pattern.matches("([a-zA-Z]+\\s+)*[a-zA-Z]+", fNameTxt.getText())) ||
            !(Pattern.matches("([a-zA-Z]+\\s+)*[a-zA-Z]+", lNameTxt.getText()))){
        
        JOptionPane.showMessageDialog(frame,
        "Tutor name should only contain valid characters.",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
    }
    
     else if(degreeBox.getSelectedItem().toString().equals("-your degree program-")){
               
        JOptionPane.showMessageDialog(frame,
        "Please select the degree program you are under.",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
         
     }
     
    else if(Float.parseFloat(CGPATxt.getText()) < 0 || Float.parseFloat(CGPATxt.getText()) > 4){
        JOptionPane.showMessageDialog(frame,
        "Make sure CGPA is between 0.0 and 4.0",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
    }
    
    else if(IDTxt.getText().length() != 8){
        JOptionPane.showMessageDialog(frame,
        "ID number should be 8 digits.",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
    }
    
     
    else if(!matchFound){
         JOptionPane.showMessageDialog(frame,
        "Invalid E-mail Address.",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
    }
        
    else{
        
    
    
    QHandler Qhandler1 = new QHandler();
    QHandler Qhandler2 = new QHandler();
    QHandler Qhandler3 = new QHandler();
    
    Qhandler1.addTutor(IDTxt.getText(), fNameTxt.getText(), mNameTxt.getText(), 
            lNameTxt.getText(), gender , degreeBox.getSelectedItem().toString(), CGPATxt.getText(), eaddTxt.getText(), remarkTxt.getText());
    Qhandler2.addContactTutor(IDTxt.getText(), contactTxt.getText());
 
    
  if((!(!(courseTxt1.getText().equals(""))) && (!(courseList1.getSelectedItem().equals("")))) 
          || (!((courseTxt1.getText().equals(""))) && ((courseList1.getSelectedItem().equals("")))))
  {
       if(courseTxt1.getText().equals(""))
       {Qhandler3.addCourseGrade(IDTxt.getText(), lNameTxt.getText(), courseList1.getSelectedItem().toString(), courseGrade1.getText());
       con3.Push(Qhandler3.query);
    
       }
       else{
           Qhandler3.addCourseGrade(IDTxt.getText(), lNameTxt.getText(), courseTxt1.getText(), courseGrade1.getText());
            con3.Push(Qhandler3.query);  
          
       }
       
         
  if((!(!(courseTxt2.getText().equals(""))) && (!(courseList2.getSelectedItem().equals("")))) 
          || (!((courseTxt2.getText().equals(""))) && ((courseList2.getSelectedItem().equals("")))))
  {
        if(courseTxt2.getText().equals(""))
       {Qhandler3.addCourseGrade(IDTxt.getText(), lNameTxt.getText(), courseList2.getSelectedItem().toString(), courseGrade2.getText());
       con3.Push(Qhandler3.query);
     
       }
       else{
           Qhandler3.addCourseGrade(IDTxt.getText(), lNameTxt.getText(), courseTxt2.getText(), courseGrade2.getText());
            con3.Push(Qhandler3.query);  
            
       }
        
        if((!(!(courseTxt3.getText().equals(""))) && (!(courseList3.getSelectedItem().equals("")))) 
          || (!((courseTxt3.getText().equals(""))) && ((courseList3.getSelectedItem().equals("")))))
  {
       if(courseTxt3.getText().equals(""))
       {Qhandler3.addCourseGrade(IDTxt.getText(), lNameTxt.getText(), courseList3.getSelectedItem().toString(), courseGrade3.getText());
       con3.Push(Qhandler3.query);
       
       }
       else{
           Qhandler3.addCourseGrade(IDTxt.getText(), lNameTxt.getText(), courseTxt3.getText(), courseGrade3.getText());
            con3.Push(Qhandler3.query);  
          
       }
        
  }
       
  }
       
        
  }
    con1.Push(Qhandler1.query);
    con2.Push(Qhandler2.query);
   
    
    con1.Disconnect(con1.rs);
    con2.Disconnect(con2.rs);
    con3.Disconnect(con3.rs);
    
    
    this.setVisible(false);
    
    AddOptions options = new AddOptions();
    options.setLocationRelativeTo(null); 
    options.setVisible(true);
    
    this.dispose();
    }
}//GEN-LAST:event_BtnSubmitActionPerformed

private void IDTxtCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_IDTxtCaretUpdate
// TODO add your handling code here:
        if(IDTxt.getText().compareTo("") == 1)
        BtnSubmit.setEnabled(true);
}//GEN-LAST:event_IDTxtCaretUpdate

private void BtnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnClearActionPerformed
// TODO add your handling code here:
    
    fNameTxt.setText("");
    mNameTxt.setText("");
    lNameTxt.setText("");
    IDTxt.setText("");
    CGPATxt.setText("");
    courseTxt1.setText("");
    courseTxt2.setText("");
    courseTxt3.setText("");
    eaddTxt.setText("");
    contactTxt.setText("");
    remarkTxt.setText("");
    buttonGroup1.clearSelection();
    courseCount = 0;
    courseTxt2.setVisible(false);
    selectLabel2.setVisible(false);
    courseGrade2.setVisible(false);
    gradeLabel2.setVisible(false);
    courseList2.setVisible(false);
    courseTxt3.setVisible(false);
    selectLabel3.setVisible(false);
    courseGrade3.setVisible(false);
    gradeLabel3.setVisible(false);
    courseList3.setVisible(false);
}//GEN-LAST:event_BtnClearActionPerformed

private void CGPATxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CGPATxtActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_CGPATxtActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    if(courseTxt3.isVisible()){
        JOptionPane.showMessageDialog(frame,
        "A tutor is only allowed to handle up to 3 subjects.",
        "Invalid",
        JOptionPane.WARNING_MESSAGE);
    }
    else if(courseCount == 0){  
        courseTxt2.setVisible(true);
        selectLabel2.setVisible(true);
        courseList2.setVisible(true);
        courseGrade2.setVisible(true);
        gradeLabel2.setVisible(true);
        courseCount++;
    }
    
    else if(courseCount == 1){
        
        courseTxt3.setVisible(true);
        selectLabel3.setVisible(true);
        courseList3.setVisible(true);
        courseGrade3.setVisible(true);
        gradeLabel3.setVisible(true);
    }
}//GEN-LAST:event_jButton1ActionPerformed


/**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AddTutor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnCancel;
    private javax.swing.JButton BtnClear;
    private javax.swing.JRadioButton BtnF;
    private javax.swing.JRadioButton BtnM;
    private javax.swing.JButton BtnSubmit;
    private javax.swing.JTextField CGPATxt;
    private javax.swing.JTextField IDTxt;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField contactTxt;
    private javax.swing.JTextField courseGrade1;
    private javax.swing.JTextField courseGrade2;
    private javax.swing.JTextField courseGrade3;
    public static javax.swing.JComboBox courseList1;
    public static javax.swing.JComboBox courseList2;
    public static javax.swing.JComboBox courseList3;
    private javax.swing.JTextField courseTxt1;
    private javax.swing.JTextField courseTxt2;
    private javax.swing.JTextField courseTxt3;
    private javax.swing.JComboBox degreeBox;
    private javax.swing.JTextField eaddTxt;
    private javax.swing.JTextField fNameTxt;
    private javax.swing.JLabel gradeLabel1;
    private javax.swing.JLabel gradeLabel2;
    private javax.swing.JLabel gradeLabel3;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField lNameTxt;
    private javax.swing.JTextField mNameTxt;
    private javax.swing.JTextField remarkTxt;
    private javax.swing.JLabel selectLabel1;
    private javax.swing.JLabel selectLabel2;
    private javax.swing.JLabel selectLabel3;
    // End of variables declaration//GEN-END:variables
}
